package com.sportizz.sport;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.TimeZone;

import org.json.JSONArray;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Instances;
import android.provider.CalendarContract.Reminders;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sportizz.model.custom_marquee_text;
import com.sportizz.model.new_ifollow_player;

public class new_Player_adapter extends BaseAdapter {

	private static final int REQ_START_STANDALONE_PLAYER = 1;
	private static final int REQ_RESOLVE_SERVICE_MISSING = 2;

	Context con;
	Activity act_con;
	List<new_ifollow_player> new_follow_match;
	// String champ_sp, player_sp, player_list, champ_list;
	DatabaseAdapter datadapter;

	// ImageLoader imgLoader;

	public new_Player_adapter(Context _context, List<new_ifollow_player> list,
			String champ_list_final, String champ_sport_final,
			String player_list_final, String player_sport_final) {

		this.con = _context;
		this.act_con = (Activity) _context;
		this.new_follow_match = list;
		// this.champ_sp = champ_sport_final;
		// this.player_sp = player_sport_final;
		// this.player_list = player_list_final;
		// this.champ_list = champ_list_final;

		datadapter = new DatabaseAdapter(con);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return new_follow_match.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@SuppressLint("NewApi")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		final LayoutInflater inflater = (LayoutInflater) con
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final ViewHolder holder;

		View view = convertView;
		if (view == null) {
			// ViewGroup viewGroup = (ViewGroup) inflater.inflate(
			// R.layout.new_ifollow, null);

			// convertView = inflater.inflate(R.layout., null);

			view = inflater.inflate(R.layout.new_ifollow, parent, false);
			holder = new ViewHolder();

			assert view != null;

			// holder = new ViewHolder(
			holder.horizontal_layout_ifollow1 = (LinearLayout) view
					.findViewById(R.id.horizontal_layout_ifollow1);
			holder.horizontal_layout_ifollow2 = (LinearLayout) view
					.findViewById(R.id.horizontal_layout_ifollow2);

			holder.txt_champ_name_ifollow = (TextView) view
					.findViewById(R.id.txt_champ_name_ifollow);
			holder.txt_sport_name_ifollow = (TextView) view
					.findViewById(R.id.txt_sport_name_ifollow);

			holder.new_layout_gap = (LinearLayout) view
					.findViewById(R.id.new_layout_gap);

			holder.video_txt_name = (TextView) view
					.findViewById(R.id.video_txt_name);

			holder.txt_tweet_ifollow = (TextView) view
					.findViewById(R.id.text_tweet_ifollow);

			holder.progress_video = (ProgressBar) view
					.findViewById(R.id.progressBar_newifollow);

			view.setTag(holder);
			// view = viewGroup;

			// HorizontalScrollView horizontal_ifollow1=(HorizontalScrollView)
			// v.findViewById(R.id.horizontal_ifollow1);
			// HorizontalScrollView horizontal_ifollow2=(HorizontalScrollView)
			// v.findViewById(R.id.horizontal_ifollow2);
		} else {
			holder = (ViewHolder) view.getTag();
			// view = convertView;
		}

		// convertView.setTag(holder);

		// txt_sport_name_ifollow.setVisibility(View.INVISIBLE);
		//
		// txt_sport_name_ifollow.setVisibility(View.INVISIBLE);

		String new_ifollow = new_follow_match.get(position).getNew_match_data();

		Log.d("suraj_", "Suraj SHinde = " + new_ifollow);

		final int row_count = new_follow_match.get(position).getnew_count();
		// final int row_count = new_follow_match.get(posi tion).getnew_count();

		final String is_team = new_follow_match.get(position).getteam_sport();

		Log.v("suraj_", "Suraj SHinde is_team = " + is_team);

		// Log.v("suraj_",
		// "Suraj SHinde Champ = "+new_follow_match.get(position).getNew_champ_data());
		Log.d("suraj_", "Suraj SHinde = " + row_count);

		final String champ_details = new_follow_match.get(position)
				.getNew_champ_data();

		final Typeface sport_font = Typeface.createFromAsset(
				act_con.getAssets(), "hel57.ttf");

		holder.txt_tweet_ifollow.setSelected(true);

		if (is_team == null && champ_details == null) {
			final String sport_list = new_follow_match.get(position)
					.getnew_video_info();

			final String[] sp_details = sport_list.split(":");

			holder.horizontal_layout_ifollow1.setVisibility(View.GONE);
			holder.new_layout_gap.setVisibility(View.GONE);
			holder.txt_tweet_ifollow.setVisibility(View.GONE);
			holder.txt_sport_name_ifollow.setVisibility(View.GONE);
			holder.txt_champ_name_ifollow.setVisibility(View.GONE);
			holder.progress_video.setVisibility(View.GONE);
			holder.video_txt_name.setVisibility(View.VISIBLE);

			holder.horizontal_layout_ifollow2.removeAllViews();
			String Json_result_iyoutube;

			String youtube_video_url = "http://sportizza.com/interface/ios_youtube_api.php?player_code=-1&champ_code=-1&"
					+ "sport_code=" + sp_details[0] + "";

			Log.d("suraj_",
					"YOUTUBE JSON IFOLLOW 22 = http://sportizza.com/interface/ios_youtube_api.php?player_code=-1&champ_code=-1&"
							+ "sport_code=" + sp_details[0] + "");

			String video_data_result = Utils.readJsonFeed(youtube_video_url,
					act_con);

			try {

				JSONArray array_entity = null;

				array_entity = new JSONArray(video_data_result);

				int array_len1 = array_entity.length();

				String play_list = null;

				boolean P_flag = true, S_flag = true, C_flag = true;

				ArrayList<String> ent_type = new ArrayList<String>();
				HashMap<String, String> play_hash = new HashMap<String, String>();

				if (array_len1 == 2) {
					for (int i = 0; i < array_len1; i++) {

						JSONObject jsonObject1 = array_entity.getJSONObject(i);

						String entity_code = jsonObject1
								.getString("ss_entity_code");

						String enity_type = jsonObject1
								.getString("ss_entity_type");

						String ss_youtube_url = jsonObject1
								.getString("ss_youtube_url");

						String pl_ls = ss_youtube_url.substring(ss_youtube_url
								.lastIndexOf("list=") + 1);

						if (entity_code.equals("ALL")) {
							// play_hash.put(enity_type,
							// pl_ls);
							// ent_type.add(enity_type);
							play_list = pl_ls;
						}

					}
					holder.video_txt_name.setText("All Sport");
					holder.video_txt_name.setTypeface(sport_font);
				} else {

					for (int i = 0; i < array_len1; i++) {

						JSONObject jsonObject1 = array_entity.getJSONObject(i);

						String entity_code = jsonObject1
								.getString("ss_entity_code");

						String enity_type = jsonObject1
								.getString("ss_entity_type");

						String ss_youtube_url = jsonObject1
								.getString("ss_youtube_url");

						String pl_ls = ss_youtube_url.substring(ss_youtube_url
								.lastIndexOf("list=") + 1);

						if (!entity_code.equals("ALL")
								|| !entity_code.equals("POP")) {
							play_hash.put(enity_type, pl_ls);
							ent_type.add(enity_type);
						}

					}

					if (ent_type.contains("S")) {
						play_list = play_hash.get("S");
						// if (ent_type.contains("C")) {
						// play_list =
						// play_hash.get("C");
						// if (ent_type.contains("P")) {
						// play_list =
						// play_hash.get("P");
						// }
						// } else if
						// (ent_type.contains("P")) {
						// play_list =
						// play_hash.get("P");
						// }

					}

					holder.video_txt_name.setText(sp_details[1]);
					holder.video_txt_name.setTypeface(sport_font);
				}

				Log.i("suraj_", "Playlist = " + play_list);

				// //////

				String[] play_list_youtube = play_list.split("=");

				Log.w("suraj_", "Video URL ="
						+ "https://gdata.youtube.com/feeds/api/playlists/"
						+ play_list_youtube[1] + "?v=2&alt=jsonc");
				// holder.horizontal_layout_ifollow2.setTag(play_list_youtube[1]);

				if (play_list != null) {
					try {
						String _response = Utils.readJsonFeed(
								"https://gdata.youtube.com/feeds/api/playlists/"
										+ play_list_youtube[1]
										+ "?v=2&alt=jsonc", con);

						JSONObject json = new JSONObject(_response);

						JSONArray jsonArray1 = json.getJSONObject("data")
								.getJSONArray("items");

						JSONObject video_array = null;
						Log.d("suraj_",
								"jsonArray1.length() = " + jsonArray1.length());

						// holder.progress_video.setVisibility(View.GONE);
						holder.horizontal_layout_ifollow2.removeAllViews();

						int ll;
						if (jsonArray1.length() > 8) {
							ll = 8;
						} else {
							ll = jsonArray1.length();
						}

						for (int i = 0; i < ll; i++) {

							JSONObject jsonObject1 = jsonArray1
									.getJSONObject(i);

							String title1 = jsonObject1.getJSONObject("video")
									.getString("title");
							// title.add(title1);
							//

							Log.d("suraj",
									"Deleted video"
											+ title1.equals("Deleted video"));

							if (title1.equals("Deleted video") == false) {
								String video_id = jsonObject1.getJSONObject(
										"video").getString("id");
								// msg.add(url);
								//
								final String thumbUrl = jsonObject1
										.getJSONObject("video")
										.getJSONObject("thumbnail")
										.getString("sqDefault");
								// thumb.add(thumbUrl);

								View additionView = inflater.inflate(
										R.layout.video_row, null, false);

								final LinearLayout linear = (LinearLayout) additionView
										.findViewById(R.id.video_lin_row);

								additionView.setTag(video_id);

								final ImageView video_thumb = (ImageView) additionView
										.findViewById(R.id.imageView_video_thumb);
								TextView video_title_thumb = (TextView) additionView
										.findViewById(R.id.txt_video_title);

								video_title_thumb.setText(title1);
								video_title_thumb.setTypeface(sport_font);
								Log.d("suraj_", "VideoTitle = " + thumbUrl);

								act_con.runOnUiThread(new Runnable() {

									@Override
									public void run() {

										DisplayImageOptions options = new DisplayImageOptions.Builder()
												.cacheInMemory(true)
												.cacheOnDisc(true)
												.showImageForEmptyUri(
														R.drawable.videos)
												.showImageOnFail(
														R.drawable.videos)
												.showImageOnLoading(
														R.drawable.videos)
												.build();

										ImageLoader.getInstance().displayImage(
												thumbUrl, video_thumb, options);

									}
								});

								holder.horizontal_layout_ifollow2
										.addView(linear);

								linear.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View arg0) {

										// TODO Auto-generated method stub
										Intent data = new Intent(act_con,
												Sample_Act_youtube.class);
										data.putExtra("video_id", linear
												.getTag().toString());
										act_con.startActivity(data);

									}

								});
							}
						}

					} catch (Exception e1) {
						e1.printStackTrace();

						Toast.makeText(con, "Error in getting data...",
								Toast.LENGTH_SHORT).show();

					}
				}

			} catch (Exception e) {
				// TODO: handle exception
			}

			String tweet_str = Utils
					.readJsonFeed(
							"http://sportizza.com/interface/ios_twitter_api.php?player_code=-1&champ_code=-1&sport_code="
									+ sp_details[0] + "", con);

			Log.d("suraj",
					"http://sportizza.com/interface/ios_twitter_api.php?player_code=-1&champ_code=-1&sport_code="
							+ sp_details[0] + "");
			holder.txt_tweet_ifollow.setVisibility(View.VISIBLE);

			Log.d("suraj", "Tweet String sport= " + tweet_str);
			try {
				if (tweet_str == null || tweet_str.equals("null")) {
					holder.txt_tweet_ifollow.setVisibility(View.GONE);
				} else {
					// holder.txt_tweet_ifollow.
					JSONArray json_arry = new JSONArray(tweet_str);

					String tweet_string = "";

					for (int i = 0; i < json_arry.length(); i++) {

						JSONObject json_object = json_arry.getJSONObject(i);

						String screen_Name = json_object
								.getString("ss_screen_name");
						String st_tweet = json_object.getString("ss_tw");

						tweet_string = tweet_string + "   "
								+ screen_Name.toUpperCase() + ": " + st_tweet;

						Log.d("suraj", "Tweet String spor for = " + i);

					}

					holder.txt_tweet_ifollow.setVisibility(View.VISIBLE);
					holder.txt_tweet_ifollow.setText(tweet_string);
					holder.txt_tweet_ifollow.setSelected(true);

				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (is_team.equals("Y") || is_team.equals("N")) {
			holder.txt_tweet_ifollow.setSelected(true);
			final String[] every_row_matchs = new_ifollow.split(";");

			String new_video = new_follow_match.get(position)
					.getnew_video_info();
			holder.video_txt_name.setVisibility(View.GONE);
			Log.v("suraj_", "Suraj SHinde new_video = " + new_video);

			// new Thread(new Runnable() {
			//
			// @Override
			// public void run() {
			//
			// act_con.runOnUiThread(new Runnable() {
			//
			// @Override
			// public void run() {
			int pos = 7;

			Log.w("suraj_", "" + every_row_matchs[1]);

			final String sport_code = every_row_matchs[3];
			final String sport_type = every_row_matchs[4];

			// holder.progress_ifollow.setVisibility(View.GONE);
			holder.horizontal_layout_ifollow1.removeAllViews();

			// txt_champ_name_ifollow.setVisibility(View.VISIBLE);
			// txt_sport_name_ifollow.setVisibility(View.VISIBLE);

			for (int i = 0; i < row_count; i++) {

				String[] match = every_row_matchs[pos].split(",");
				String[] match_player = match[1].split(":");

				final String player_1 = match_player[1];
				String player1_country = match_player[2];
				String player1_club = match_player[3];

				final String player_2 = match_player[5];
				String player2_country = match_player[6];
				String player2_club = match_player[7];

				final String player_3 = match_player[9];
				final String player_4 = match_player[11];

				String p1_code = match_player[0];
				String p2_code = match_player[4];
				String p3_code = match_player[8];
				String p4_code = match_player[10];

				final String tick_url = every_row_matchs[pos + 2];

				String date_string = every_row_matchs[pos + 1];

				final String[] day_date = date_string.split(",");

				String[] channel_details = every_row_matchs[pos + 3].split(",");

				String[] channels = channel_details[1].split(":");

				String chan1 = channels[0];
				String chan2 = channels[1];
				String chan3 = channels[2];

				View additionView = inflater.inflate(
						R.layout.new_hori_player_row, null, false);

				final RelativeLayout linear = (RelativeLayout) additionView
						.findViewById(R.id.new_hori_player_layout);

				final ImageView new_img_p1 = (ImageView) additionView
						.findViewById(R.id.new_image_p1_hor);
				final ImageView new_img_p2 = (ImageView) additionView
						.findViewById(R.id.new_image_p2_hor);

				Button btn_ticket = (Button) additionView
						.findViewById(R.id.ticket_player_hor);
				Button btn_cal_add = (Button) additionView
						.findViewById(R.id.new_btn_player_addcal_hor);

				TextView game = (TextView) additionView
						.findViewById(R.id.new_txt_game_hor);
				TextView match_tx = (TextView) additionView
						.findViewById(R.id.new_txt_match_hor);

				game.setTypeface(sport_font);
				match_tx.setTypeface(sport_font);

				String url = null;
				// ImageLoader imloader=new
				// ImageLoader(con.getApplicationContext());

				// /////

				if (i == row_count - 1) {
					additionView.findViewById(R.id.gap).setVisibility(
							View.INVISIBLE);
				}

				// InputStream iss = null;
				// try {
				// iss = con.getResources().getAssets()
				// .open("new_sports/" + sport_code + ".png");
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// try {
				// iss = con.getResources().getAssets()
				// .open("new_sports/GAM.png");
				// } catch (IOException e) {
				// e.printStackTrace();
				// }
				// }
				// Bitmap result1 = BitmapFactory.decodeStream(iss);
				//
				// Bitmap output = null;
				// Canvas canvas;
				// float roundPx;
				//
				// output = Bitmap.createBitmap(result1.getWidth(),
				// result1.getHeight(), Bitmap.Config.ARGB_8888);
				// canvas = new Canvas(output);
				//
				// Paint paint = new Paint();
				// Rect rect = new Rect(0, 0, result1.getWidth(),
				// result1.getHeight());
				// RectF rectF = new RectF(rect);
				// roundPx = 8f;
				//
				// paint.setAntiAlias(true);
				// canvas.drawARGB(0, 0, 0, 0);
				// paint.setColor(0xff424242);
				// canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
				// paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
				// canvas.drawBitmap(result1, rect, rect, paint);

				int resourceId = act_con.getResources().getIdentifier(
						sport_code, "id", act_con.getPackageName());
				if (resourceId == 0) {
					resourceId = R.drawable.gam;
				}
				new_img_p1.setImageResource(resourceId);
				// new_img_p1.setScaleType(ScaleType.FIT_CENTER);

				new_img_p2.setImageResource(resourceId);
				// new_img_p2.setScaleType(ScaleType.FIT_CENTER);

				// //

				String game_txt = "";

				if (sport_type.equalsIgnoreCase("N")) {

					String[] game_match = every_row_matchs[pos + 4].split(":");

					game_txt = game_match[0];

					Log.w("suraj", "game_txtu  = " + game_txt + " match_txu = "
							+ game_match[1]);

					if (game_txt.equals("") || game_txt == null
							|| game_txt.contains("null")) {
						game.setText("");
					} else {
						game.setText(game_txt);
					}

					if (game_match[1].equals("") || game_match[1] == null
							|| game_match[1].contains("null")) {
						match_tx.setText("");
					} else {
						match_tx.setText(game_match[1]);
					}

					if (game_txt.contains("Doubles")) {
						additionView.findViewById(R.id.tableRow3)
								.setVisibility(View.VISIBLE);
						// Bitmap result = null;
						// InputStream is = null;
						// try {
						// is = con.getAssets().open(
						// "new_sports/" + sport_code + ".png");
						//
						// result = BitmapFactory.decodeStream(is);
						//
						// } catch (Exception e) {
						// try {
						// is = con.getResources().getAssets()
						// .open("new_sports/GAM.png");
						//
						// result = BitmapFactory.decodeStream(is);
						// } catch (IOException e1) {
						// e1.printStackTrace();
						// }
						//
						// }
						//
						// Bitmap output1 = null;
						// Canvas canvas1;
						// // float roundPx1;
						//
						// output1 = Bitmap.createBitmap(result.getWidth(),
						// result.getHeight(), Bitmap.Config.ARGB_8888);
						// canvas = new Canvas(output1);
						//
						// Paint paint1 = new Paint();
						// Rect rect1 = new Rect(0, 0, result.getWidth(),
						// result.getHeight());
						// RectF rectF1 = new RectF(rect1);
						// roundPx = 8f;
						//
						// paint1.setAntiAlias(true);
						// canvas.drawARGB(0, 0, 0, 0);
						// paint1.setColor(0xff424242);
						// canvas.drawRoundRect(rectF1, roundPx, roundPx,
						// paint1);
						// paint1.setXfermode(new
						// PorterDuffXfermode(Mode.SRC_IN));
						// canvas.drawBitmap(result, rect1, rect1, paint1);

						new_img_p1.setImageResource(resourceId);
						// new_img_p1.setScaleType(ScaleType.FIT_CENTER);

						new_img_p2.setImageResource(resourceId);
						// new_img_p2.setScaleType(ScaleType.FIT_CENTER);

					} else {
						additionView.findViewById(R.id.tableRow3)
								.setVisibility(View.GONE);

						final String p1_url = StartActivity.get_img_location
								+ "phone/country/" + player1_country + ".png";

						// new imageTask(new_img_p1, sport_code)
						// .execute(url);

						final String p2_url = StartActivity.get_img_location
								+ "phone/country/" + player2_country + ".png";

						// imgLoader.DisplayImage(url2,
						// loader_row, new_img_p2);

						// new imageTask(new_img_p2, sport_code)
						// .execute(url);

						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {

								int loader = getImgLoader(sport_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(p1_url,
										new_img_p1, options);
								ImageLoader.getInstance().displayImage(p1_url,
										new_img_p2, options);

							}
						});

					}
				} else if (sport_type.equalsIgnoreCase("Y")) {
					// game_txt = every_row_matchs[pos + 4];

					String[] game_match = every_row_matchs[pos + 4].split(":");

					game_txt = game_match[0];

					Log.w("suraj", "game_txtu  = " + game_txt + " match_txu = "
							+ game_match[1]);

					if (game_txt.equals("") || game_txt == null) {
						game.setText("");
					} else {
						game.setText(game_txt);
					}

					if (game_match[1].equals("") || game_match[1] == null) {
						match_tx.setText("");
					} else {
						match_tx.setText(game_match[1]);
					}

					additionView.findViewById(R.id.tableRow3).setVisibility(
							View.GONE);
					if (player1_club.equalsIgnoreCase(player1_country)) {

						final String p1_url = StartActivity.get_img_location
								+ "phone/country/" + player1_country + ".png";

						// new imageTask(new_img_p1, sport_code)
						// .execute(url);
						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {
								int loader = getImgLoader(sport_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(p1_url,
										new_img_p1, options);
							}
						});
					} else {
						final String p1_url = StartActivity.get_img_location
								+ "phone/" + sport_code + "/" + p1_code
								+ ".png";
						// new imageTask(new_img_p1, sport_code)
						// .execute(url);

						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {
								int loader = getImgLoader(sport_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(p1_url,
										new_img_p1, options);

							}
						});
					}

					if (player2_club.equalsIgnoreCase(player2_country)) {
						final String p2_url = StartActivity.get_img_location
								+ "phone/country/" + player2_country + ".png";

						// new imageTask(new_img_p2, sport_code)
						// .execute(url);

						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {
								int loader = getImgLoader(sport_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(p2_url,
										new_img_p2, options);
							}
						});

					} else {
						final String p2_url = StartActivity.get_img_location
								+ "phone/" + sport_code + "/" + p2_code
								+ ".png";

						// new imageTask(new_img_p2, sport_code)
						// .execute(url);
						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {
								int loader = getImgLoader(sport_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(p2_url,
										new_img_p2, options);

							}
						});

					}
				}

				TextView player1 = (TextView) additionView
						.findViewById(R.id.new_txt_player1_hor);
				player1.setText(player_1);
				player1.setSelected(true);
				player1.setTypeface(sport_font);

				TextView player2 = (TextView) additionView
						.findViewById(R.id.new_txt_player2_hor);
				player2.setText(player_2);
				player2.setSelected(true);
				player2.setTypeface(sport_font);

				TextView player3 = (TextView) additionView
						.findViewById(R.id.new_txt_player3_hor);
				player3.setText(player_3);
				player3.setSelected(true);
				player3.setTypeface(sport_font);

				TextView player4 = (TextView) additionView
						.findViewById(R.id.new_txt_player4_hor);
				player4.setText(player_4);
				player4.setSelected(true);
				player4.setTypeface(sport_font);

				TextView new_txt_pday_hor = (TextView) additionView
						.findViewById(R.id.new_txt_pday_hor);

				new_txt_pday_hor.setText(day_date[0]);
				new_txt_pday_hor.setTypeface(sport_font);

				TextView new_txt_pdate_hor = (TextView) additionView
						.findViewById(R.id.new_txt_pdate_hor);

				String[] ddate = day_date[1].split(" ");

				new_txt_pdate_hor.setText(ddate[0] + "\n" + ddate[1] + " "
						+ ddate[2]);

				new_txt_pdate_hor.setTypeface(sport_font);

				Button new_btn_p_follow1_hor = (Button) additionView
						.findViewById(R.id.new_btn_p_follow1_hor);
				new_btn_p_follow1_hor.setTag(p1_code + ":" + player_1 + ":"
						+ sport_code + ":" + every_row_matchs[1] + ":"
						+ player1_country + ":" + p3_code + ":" + player_3
						+ ":" + sport_code + ":" + every_row_matchs[1]);

				Button new_btn_p_follow2_hor = (Button) additionView
						.findViewById(R.id.new_btn_p_follow2_hor);

				new_btn_p_follow2_hor.setTag(p2_code + ":" + player_2 + ":"
						+ sport_code + ":" + every_row_matchs[1] + ":"
						+ player2_country + ":" + p4_code + ":" + player_4
						+ ":" + sport_code + ":" + every_row_matchs[1]);

				// ///////////
				btn_ticket.setTypeface(sport_font);

				btn_ticket.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						try {
							if (!tick_url.equals("") || tick_url != null
									|| tick_url.length() != 0) {

								Fb_dialog_box pdb = new Fb_dialog_box(con,
										tick_url);
								pdb.show();

							} else {

								Toast.makeText(con, "Check after some time",
										Toast.LENGTH_LONG).show();

							}
						} catch (Exception e) {

							Toast.makeText(con, "Check after some time",
									Toast.LENGTH_SHORT).show();

						}
					}
				});

				final String game_text = game_txt;

				btn_cal_add.setTypeface(sport_font);

				btn_cal_add.setOnClickListener(new OnClickListener() {

					@SuppressLint("NewApi")
					@Override
					public void onClick(View v) {

						String date_str = day_date[2];

						Log.v("suraj", "DAte = " + date_str);

						Long start_date_mili = null;

						String title = null;

						if (game_text.contains("Double") == true) {
							title = player_1 + " / " + player_3 + " Vs "
									+ player_2 + " / " + player_4 + " - "
									+ every_row_matchs[1];
						} else {
							title = player_1 + " Vs " + player_2 + " - "
									+ every_row_matchs[1];
						}

						String Desc = "SPORTIZZA";

						SimpleDateFormat dateFormat11 = new SimpleDateFormat(
								"dd-MM-yyyy hh:mm a");

						Date date11 = null;

						try {
							date11 = dateFormat11.parse(date_str);
						} catch (ParseException e) {
							e.printStackTrace();
						}

						start_date_mili = date11.getTime();

						try {

							long begin = start_date_mili;
							long end = start_date_mili + 30 * 60 * 1000;// ending
																		// time
																		// in
																		// milliseconds
							String[] proj = new String[] { Instances._ID,
									Instances.BEGIN, Instances.END,
									Instances.EVENT_ID };

							Cursor cursor = Instances.query(
									act_con.getContentResolver(), proj, begin,
									end);

							cursor.moveToFirst();

							if (cursor.getCount() > 0) {

								String title_cal = cursor.getString(cursor
										.getColumnIndex("title"));

								if (title_cal.equals(title)) {
									Log.i("suraj",
											"Cursor = "
													+ cursor.getString(cursor
															.getColumnIndex("title")));

									Toast.makeText(act_con,
											"Already Added to Calendar..",
											Toast.LENGTH_SHORT).show();
								} else {
									Log.i("suraj", "Add to calendar = " + title);

									if (sport_type.equalsIgnoreCase("N")) {
										addToCalendar(
												con,
												title,
												Desc,
												start_date_mili,
												start_date_mili + 30 * 60 * 1000);
										Toast.makeText(act_con,
												"Added to Calender..",
												Toast.LENGTH_SHORT).show();
									} else {
										addToCalendar_team(
												con,
												every_row_matchs[1],
												game_text,
												title,
												start_date_mili,
												start_date_mili + 30 * 60 * 1000);
									}
								}
							} else {
								Log.i("suraj", "Add to calendar = " + title);
								if (sport_type.equalsIgnoreCase("N")) {
									addToCalendar(con, title, Desc,
											start_date_mili,
											start_date_mili + 30 * 60 * 1000);
									Toast.makeText(act_con,
											"Added to Calender..",
											Toast.LENGTH_SHORT).show();
								} else {
									addToCalendar_team(con,
											every_row_matchs[1], game_text,
											title, start_date_mili,
											start_date_mili + 30 * 60 * 1000);
									Toast.makeText(act_con,
											"Added to Calender..",
											Toast.LENGTH_SHORT).show();
								}

							}
						} catch (Exception e) {
							e.printStackTrace();
						}

					}

					@SuppressWarnings("deprecation")
					@SuppressLint("NewApi")
					public void addToCalendar(Context ctx, final String title,
							final String desc, final long dtstart,
							final long dtend) {

						Uri eventsUri, reminderuri;

						if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 14) {
							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");

							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, title);
							event.put(Events.DESCRIPTION, desc);
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.EVENT_COLOR, Color.RED);

							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							// To Insert
							Log.v("suraj", "Event ="
									+ TimeZone.getDefault().getID());

							Uri uri = ctx.getContentResolver().insert(
									CalendarContract.Events.CONTENT_URI, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(
									CalendarContract.Reminders.CONTENT_URI,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);

						} else if (Integer
								.parseInt(android.os.Build.VERSION.SDK) >= 8
								&& Integer
										.parseInt(android.os.Build.VERSION.SDK) < 14) {

							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");
							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, title);
							event.put(Events.DESCRIPTION, desc);
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							Log.v("suraj", "Event ="
									+ TimeZone.getDefault().getID());

							Uri uri = ctx.getContentResolver().insert(
									eventsUri, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(reminderuri,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);
						}
					}

					@SuppressWarnings("deprecation")
					@SuppressLint("NewApi")
					public void addToCalendar_team(Context ctx,
							final String title, final String desc,
							final String tit, final long dtstart,
							final long dtend) {

						Uri eventsUri, reminderuri;

						if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 14) {
							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");
							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, tit);
							event.put(Events.DESCRIPTION, "SPORTIZZA");
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.EVENT_COLOR, Color.BLUE);
							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							// To Insert
							Log.v("suraj", "Event ="
									+ TimeZone.getDefault().getID());

							Uri uri = ctx.getContentResolver().insert(
									CalendarContract.Events.CONTENT_URI, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(
									CalendarContract.Reminders.CONTENT_URI,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);

						} else if (Integer
								.parseInt(android.os.Build.VERSION.SDK) >= 8
								&& Integer
										.parseInt(android.os.Build.VERSION.SDK) < 14) {
							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");

							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, tit);
							event.put(Events.DESCRIPTION, "SPORTIZZA");
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							// To Insert
							Log.v("suraj", "Event ="
									+ TimeZone.getDefault().getID());

							Uri uri = ctx.getContentResolver().insert(
									eventsUri, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(reminderuri,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);
						}
					}
				});

				if (sport_type.equalsIgnoreCase("N")) {

					String game_txt1 = every_row_matchs[pos + 4];

					if (game_txt1.contains("Double") == true) {
						new_btn_p_follow1_hor.setText("FOLLOW");
						new_btn_p_follow2_hor.setText("FOLLOW");
					} else {
						Log.d("suraj", "playerAll = " + MainActivity.playerAll);

						if (MainActivity.playerAll != null) {
							String[] b1_tag = new_btn_p_follow1_hor.getTag()
									.toString().split(":");
							String[] b2_tag = new_btn_p_follow2_hor.getTag()
									.toString().split(":");

							if (MainActivity.playerAll.contains(b1_tag[0]) == true) {
								new_btn_p_follow1_hor.setText("UNFOLLOW");
							} else {
								new_btn_p_follow1_hor.setText("FOLLOW");
							}

							if (MainActivity.playerAll.contains(b2_tag[0]) == true) {
								new_btn_p_follow2_hor.setText("UNFOLLOW");
							} else {
								new_btn_p_follow2_hor.setText("FOLLOW");
							}
						}
					}
				} else {
					if (MainActivity.playerAll != null) {
						String[] b1_tag = new_btn_p_follow1_hor.getTag()
								.toString().split(":");
						String[] b2_tag = new_btn_p_follow2_hor.getTag()
								.toString().split(":");

						if (MainActivity.playerAll.contains(b1_tag[0]) == true) {
							new_btn_p_follow1_hor.setText("UNFOLLOW");
						} else {
							new_btn_p_follow1_hor.setText("FOLLOW");
						}

						if (MainActivity.playerAll.contains(b2_tag[0]) == true) {
							new_btn_p_follow2_hor.setText("UNFOLLOW");
						} else {
							new_btn_p_follow2_hor.setText("FOLLOW");
						}
					}
				}

				// //////

				TextView ch1 = (TextView) additionView
						.findViewById(R.id.new_img_p_channel2_hor);

				if (chan1.equals("null") || chan1.equals("NONE")
						|| chan1 == null) {
					ch1.setText("");
				} else {
					ch1.setText(chan1);
					ch1.setTypeface(sport_font);
				}

				TextView ch2 = (TextView) additionView
						.findViewById(R.id.new_img_p_channel1_hor);
				if (chan2.equals("null") || chan2.equals("NONE")
						|| chan2 == null) {
					ch2.setText("");
				} else {
					ch2.setText(chan2);
					ch2.setTypeface(sport_font);
				}

				TextView ch3 = (TextView) additionView
						.findViewById(R.id.new_img_p_channel3_hor);

				Log.i("suraj", "Chan 3 == " + chan3.equals("null"));
				Log.v("suraj", "Chan 3 == " + chan3.equals(null));

				if (chan3.equals("NONE") || chan3.equals("null")
						|| chan3 == null) {
					ch3.setText("");
				} else {
					ch3.setText(chan3);
					ch3.setTypeface(sport_font);
				}
				// Button new_btn_player_addcal_hor = (Button)
				// additionView
				// .findViewById(R.id.new_btn_player_addcal_hor);
				// Button ticket_player_hor = (Button)
				// additionView
				// .findViewById(R.id.ticket_player_hor);

				pos += 6;

				holder.horizontal_layout_ifollow1.addView(linear);

			}

			holder.txt_champ_name_ifollow.setText(every_row_matchs[1]);
			holder.txt_champ_name_ifollow.setTypeface(sport_font);
			Bitmap bi_result = null;

			try {
				bi_result = BitmapFactory.decodeStream(con.getResources()
						.getAssets()
						.open("sport_small/" + sport_code + "_S.png"));
			} catch (IOException e1) {
				e1.printStackTrace();
				try {
					bi_result = BitmapFactory.decodeStream(con.getResources()
							.getAssets().open("sport_small/GAM_S.png"));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			if (bi_result == null) {
				holder.txt_champ_name_ifollow
						.setCompoundDrawablesWithIntrinsicBounds(
								R.drawable.team_selected, 0, 0, 0);

				holder.txt_champ_name_ifollow
						.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
			} else {
				Bitmap bitmap = Bitmap.createScaledBitmap(bi_result, 30, 30,
						true);

				Drawable tmpDraw = (Drawable) new BitmapDrawable(
						con.getResources(), bitmap);

				holder.txt_champ_name_ifollow
						.setCompoundDrawablesWithIntrinsicBounds(tmpDraw, null,
								null, null);
			}

			holder.txt_sport_name_ifollow.setText(every_row_matchs[2]);

			holder.txt_sport_name_ifollow.setTypeface(sport_font);
			String tweet_str = Utils.readJsonFeed(
					"http://sportizza.com/interface/ios_twitter_api.php?player_code="
							+ every_row_matchs[5]
							+ "&champ_code=-1&sport_code=-1", con);

			holder.txt_tweet_ifollow.setSelected(true);

			Log.d("suraj", "Tweet String = " + tweet_str);

			if (tweet_str == null || tweet_str.equals("null")) {
				holder.txt_tweet_ifollow.setVisibility(View.GONE);
			} else {
				try {

					JSONArray json_arry = new JSONArray(tweet_str);

					String tweet_string = "";

					for (int i = 0; i < json_arry.length(); i++) {

						JSONObject json_object = json_arry.getJSONObject(i);

						String screen_Name = json_object
								.getString("ss_screen_name");
						String st_tweet = json_object.getString("ss_tw");

						tweet_string = tweet_string + "   "
								+ screen_Name.toUpperCase() + ": " + st_tweet;

					}

					holder.txt_tweet_ifollow.setVisibility(View.VISIBLE);

					holder.txt_tweet_ifollow.setText(tweet_string);
					holder.txt_tweet_ifollow.setSelected(true);
				} catch (Exception e) {
				}
			}

			// }
			//
			// });
			//
			// }
			// }).start();

			if (new_video != null) {
				// Thread t = new Thread(new Runnable() {
				//
				// @Override
				// public void run() {
				//
				// act_con.runOnUiThread(new Runnable() {
				//
				// @Override
				// public void run() {

				holder.horizontal_layout_ifollow2.removeAllViews();

				String Json_result_iyoutube = null;

				// if(champ_sp==""&&player_sp=="")
				// {
				// Json_result_iyoutube =
				// Utils.readJsonFeed("http://sportizza.com/interface/ios_youtube_api.php?player_code="+player_list+"&champ_code="+champ_list+"&sport_code=-1",con);
				//
				// Log.d("suraj_","YOUTUBE JSON IFOLLOW ="+"http://sportizza.com/interface/ios_youtube_api.php?player_code="+player_list+"&champ_code="+champ_list+"&sport_code=-1");
				// }
				// else
				// {
				String Follow_pl_tm = every_row_matchs[5];

				String pl_tm_sport_f = "-1";

				datadapter.open();

				Cursor get_sport_follow = datadapter
						.getfollowersport(Follow_pl_tm);
				get_sport_follow.moveToFirst();

				datadapter.close();

				if (get_sport_follow.getCount() > 0) {
					do {
						pl_tm_sport_f = get_sport_follow
								.getString(get_sport_follow
										.getColumnIndex("sport_code"));
					} while (get_sport_follow.moveToNext());

				}

				String youtube_video_url = "http://sportizza.com/interface/ios_youtube_api.php?player_code="
						+ Follow_pl_tm
						+ "&champ_code="
						+ every_row_matchs[0]
						+ "&sport_code=" + pl_tm_sport_f + "";

				Log.d("suraj_",
						"YOUTUBE JSON IFOLLOW 22="
								+ "http://sportizza.com/interface/ios_youtube_api.php?player_code="
								+ Follow_pl_tm + "&champ_code="
								+ every_row_matchs[0] + "&sport_code="
								+ pl_tm_sport_f + "");

				String video_data_result = Utils.readJsonFeed(
						youtube_video_url, con);
				;

				try {

					JSONArray array_entity = null;

					array_entity = new JSONArray(video_data_result);

					int array_len1 = array_entity.length();

					String play_list = null;

					boolean P_flag = true, S_flag = true, C_flag = true;

					ArrayList<String> ent_type = new ArrayList<String>();
					HashMap<String, String> play_hash = new HashMap<String, String>();

					for (int i = 0; i < array_len1; i++) {

						JSONObject jsonObject1 = array_entity.getJSONObject(i);

						String entity_code = jsonObject1
								.getString("ss_entity_code");

						String enity_type = jsonObject1
								.getString("ss_entity_type");

						String ss_youtube_url = jsonObject1
								.getString("ss_youtube_url");

						String pl_ls = ss_youtube_url.substring(ss_youtube_url
								.lastIndexOf("list=") + 1);

						if (!entity_code.equals("ALL")
								|| !entity_code.equals("POP")) {
							play_hash.put(enity_type, pl_ls);
							ent_type.add(enity_type);
						}

					}

					if (ent_type.contains("S")) {
						play_list = play_hash.get("S");
						if (ent_type.contains("C")) {
							play_list = play_hash.get("C");
							if (ent_type.contains("P")) {
								play_list = play_hash.get("P");
							}
						} else if (ent_type.contains("P")) {
							play_list = play_hash.get("P");
						}

					}

					Log.i("suraj_", "Playlist = " + play_list);

					// //////

					String[] play_list_youtube = play_list.split("=");

					Log.w("suraj_", "Video URL ="
							+ "https://gdata.youtube.com/feeds/api/playlists/"
							+ play_list_youtube[1] + "?v=2&alt=jsonc");
					// holder.horizontal_layout_ifollow2.setTag(play_list_youtube[1]);

					if (play_list != null) {
						try {
							String _response = Utils.readJsonFeed(
									"https://gdata.youtube.com/feeds/api/playlists/"
											+ play_list_youtube[1]
											+ "?v=2&alt=jsonc", con);

							JSONObject json = new JSONObject(_response);

							JSONArray jsonArray1 = json.getJSONObject("data")
									.getJSONArray("items");

							JSONObject video_array = null;
							Log.d("sms",
									"jsonArray1.length() = "
											+ jsonArray1.length());

							// holder.progress_video.setVisibility(View.GONE);
							holder.horizontal_layout_ifollow2.removeAllViews();
							Random r = new Random();

							// JSONArray temp_array =
							// jsonArray1.getJSONArray(r.nextInt(jsonArray1.length()));

							// Log.d("sms",
							// "jsonArray1.length() = "
							// + temp_array.length());

							int ll;
							if (jsonArray1.length() > 8) {
								ll = 8;
							} else {
								ll = jsonArray1.length();
							}

							for (int i = 0; i < ll; i++) {

								JSONObject jsonObject1 = jsonArray1
										.getJSONObject(i);

								String title1 = jsonObject1.getJSONObject(
										"video").getString("title");
								// title.add(title1);
								//
								if (!title1.equals("Deleted video")) {
									String video_id = jsonObject1
											.getJSONObject("video").getString(
													"id");
									// msg.add(url);
									//
									final String thumbUrl = jsonObject1
											.getJSONObject("video")
											.getJSONObject("thumbnail")
											.getString("sqDefault");
									// thumb.add(thumbUrl);

									View additionView = inflater.inflate(
											R.layout.video_row, null, false);

									final LinearLayout linear = (LinearLayout) additionView
											.findViewById(R.id.video_lin_row);

									additionView.setTag(video_id);

									final ImageView video_thumb = (ImageView) additionView
											.findViewById(R.id.imageView_video_thumb);
									TextView video_title_thumb = (TextView) additionView
											.findViewById(R.id.txt_video_title);

									video_title_thumb.setText(title1);

									video_title_thumb.setTypeface(sport_font);
									Log.d("suraj_", "VideoTitle = " + thumbUrl);

									act_con.runOnUiThread(new Runnable() {

										@Override
										public void run() {
											int loader = R.drawable.videos;

											DisplayImageOptions options = new DisplayImageOptions.Builder()
													.cacheInMemory(true).cacheOnDisc(true)
													.showImageForEmptyUri(loader)
													.showImageOnFail(loader)
													.showImageOnLoading(loader).build();

											ImageLoader.getInstance().displayImage(thumbUrl,
													video_thumb, options);

										}
									});

									holder.horizontal_layout_ifollow2
											.addView(linear);

									linear.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View arg0) {

											// TODO Auto-generated method stub
											Intent data = new Intent(act_con,
													Sample_Act_youtube.class);
											data.putExtra("video_id", linear
													.getTag().toString());
											act_con.startActivity(data);

										}

									});
								}
							}

						} catch (Exception e1) {
							e1.printStackTrace();
						}
					} else {
						holder.horizontal_layout_ifollow2
								.setVisibility(View.GONE);
						holder.new_layout_gap.setVisibility(View.GONE);
					}
					// /////

				} catch (Exception e) {
					// TODO: handle exception
				}

				// }
				// });
				//
				// }
				// });
				// t.start();
			} else {
				holder.horizontal_layout_ifollow2.setVisibility(View.GONE);
				holder.new_layout_gap.setVisibility(View.GONE);
			}
			// return null;
			//
			// }
			// };
			// wait1.execute();
		} else if (is_team.equals("A")) {

			holder.video_txt_name.setVisibility(View.GONE);
			holder.txt_tweet_ifollow.setSelected(true);

			Log.d("suraj_", "Suraj SHinde champ_details= " + champ_details);

			String new_video = new_follow_match.get(position)
					.getnew_video_info();

			Log.v("suraj_", "Suraj SHinde new_video = " + new_video);

			// new Thread(new Runnable() {
			//
			// @Override
			// public void run() {
			//
			// act_con.runOnUiThread(new Runnable() {
			//
			// @Override
			// public void run() {
			final String[] champ_data = champ_details.split(";");

			int pos = 4;

			// int champ_count=0 ;//=
			// new_follow_match.get(position).getnew_champ_count();
			holder.horizontal_layout_ifollow1.removeAllViews();

			Log.d("suraj", "row_count Matchs==" + row_count);

			holder.txt_champ_name_ifollow.setText(champ_data[1]);
			holder.txt_champ_name_ifollow.setTypeface(sport_font);

			holder.txt_sport_name_ifollow.setText(champ_data[2]);
			holder.txt_sport_name_ifollow.setTypeface(sport_font);

			final String sp_code = champ_data[3];

			for (int j = 0; j < row_count; j++) {
				View add_View = inflater.inflate(R.layout.new_hori_champ_row,
						null, false);

				final RelativeLayout linear = (RelativeLayout) add_View
						.findViewById(R.id.new_hori_champ_layout);

				LinearLayout linear_main = (LinearLayout) add_View
						.findViewById(R.id.linear_main);

				RelativeLayout relativeLayout1 = (RelativeLayout) add_View
						.findViewById(R.id.relativeLayout1_hori);

				Button new_btn_c_follow_hor = (Button) add_View
						.findViewById(R.id.new_btn_c_follow_hor);

				new_btn_c_follow_hor.setVisibility(View.GONE);

				if (j == row_count - 1) {
					add_View.findViewById(R.id.gap_champ).setVisibility(
							View.INVISIBLE);
				}

				LayoutParams lparams = new LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

				String match_details = champ_data[pos];

				Log.d("suraj", pos + "Suraj SHINDE Match_details=="
						+ match_details);

				pos++;

				final String[] match = match_details.split("!");

				TextView game_txt = (TextView) add_View
						.findViewById(R.id.new_text_game);
				game_txt.setSelected(true);
				game_txt.setText(match[1]);
				game_txt.setTypeface(sport_font);
				String channels = match[2];

				String[] ch = channels.split(",");

				String[] chan = ch[1].split(":");

				Log.w("suraj", "Channel = " + ch[1]);

				String channel1 = chan[0];
				String channel2 = chan[1];
				String channel3 = chan[2];

				final String[] ticket = match[0].split(",");

				Log.v("suraj", "game_txt==" + match.length);

				if (match.length > 8) {
					RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(
							LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT);

					relativeLayout1.setLayoutParams(adaptLayout);
				}

				for (int i = 0; i < match.length; i++) {

					if (match[i] != null) {
						if (match[i].contains("date")) {
							String[] champ_d = match[i].split(",");

							com.sportizz.model.custom_marquee_text tv = new custom_marquee_text(
									act_con);
							// TextView tv = new TextView(act_con);
							tv.setLayoutParams(lparams);
							tv.setText(champ_d[1]);
							tv.setTypeface(sport_font);
							tv.setTextSize(11);
							tv.setFocusable(true);
							tv.setFocusableInTouchMode(true);
							tv.setSingleLine(true);
							tv.setTextColor(Color.parseColor("#FFCC11"));
							linear_main.addView(tv);
						} else if (match[i].contains("time")) {
							String[] champ_d = match[i].split(",");
							com.sportizz.model.custom_marquee_text tv = new custom_marquee_text(
									act_con);
							// TextView tv = new TextView(act_con);
							lparams.setMargins(20, 0, 0, 0);
							tv.setTextSize(11);
							tv.setLayoutParams(lparams);
							tv.setText(champ_d[1]);
							tv.setFocusable(true);
							tv.setTextColor(Color.WHITE);
							tv.setFocusableInTouchMode(true);
							tv.setSingleLine(true);
							tv.setTypeface(sport_font);
							linear_main.addView(tv);
						}
					}
				}

				final Button ticket_btn = (Button) add_View
						.findViewById(R.id.ticket_champ_hor);

				ticket_btn.setTypeface(sport_font);

				ticket_btn.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {

						try {

							if (!ticket[0].equals("") || ticket[0] != null
									|| ticket[0].length() != 0) {

								Fb_dialog_box pdb = new Fb_dialog_box(con,
										ticket[0]);
								pdb.show();

							} else {

								Toast.makeText(con, "Check after some time",
										Toast.LENGTH_LONG).show();

							}
						} catch (Exception e) {

							Toast.makeText(con, "Check after some time",
									Toast.LENGTH_SHORT).show();

						}

					}
				});

				final Button btn_cal_champ = (Button) add_View
						.findViewById(R.id.new_btn_champ_addcal_hor);

				btn_cal_champ.setTag(match[3]);
				// String My_date_cal = match[3];
				btn_cal_champ.setTypeface(sport_font);

				btn_cal_champ.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {

						String date_str = (String) btn_cal_champ.getTag();

						Log.v("suraj", "DAte = " + date_str);

						Long start_date_mili = null;

						String title = match[1] + " - " + champ_data[1];

						SimpleDateFormat dateFormat11 = new SimpleDateFormat(
								"dd-MM-yyyy hh:mm a");

						Date date11 = null;

						try {
							date11 = dateFormat11.parse(date_str);
						} catch (ParseException e) {
							e.printStackTrace();
						}

						start_date_mili = date11.getTime();

						long begin = start_date_mili;
						long end = start_date_mili + 30 * 60 * 1000;// ending
																	// time

						try {

							String[] proj = new String[] { Instances._ID,
									Instances.BEGIN, Instances.END,
									Instances.EVENT_ID };

							Cursor cursor = Instances.query(
									con.getContentResolver(), proj, begin, end);

							cursor.moveToFirst();

							Log.v("suraj", "Cursor = " + cursor);

							Log.v("suraj",
									"Cursor COUNT = " + cursor.getCount());

							if (cursor.getCount() > 0) {
								String title_cal = cursor.getString(cursor
										.getColumnIndex("title"));

								if (title_cal.equals(title)) {
									Log.i("suraj",
											"Cursor = "
													+ cursor.getString(cursor
															.getColumnIndex("title")));

									Toast.makeText(con,
											"Already Added to Calendar..",
											Toast.LENGTH_SHORT).show();
								} else {
									Log.i("suraj",
											"Setting_Act.check_cal.isChecked() = "
													+ Setting_Act.check_cal
															.isChecked());

									Log.i("suraj", "Add to calendar = " + title);

									addToCalendar_champ(con, champ_data[1],
											match[1], title, start_date_mili,
											start_date_mili + 30 * 60 * 1000);
									Toast.makeText(con, "Added to Calendar..",
											Toast.LENGTH_SHORT).show();

								}
							} else {

								Log.i("suraj", "Add to calendar = " + title);

								addToCalendar_champ(con, champ_data[1],
										match[1], title, start_date_mili,
										start_date_mili + 30 * 60 * 1000);
								Toast.makeText(con, "Added to Calendar..",
										Toast.LENGTH_SHORT).show();
							}
							// } else {
							// Toast.makeText(act_context,
							// "Access Calendar is off in setting",
							// Toast.LENGTH_SHORT).show();
							// }
						} catch (Exception e) {
							e.printStackTrace();

							addToCalendar_champ(con, champ_data[1], match[1],
									title, start_date_mili,
									start_date_mili + 30 * 60 * 1000);
							Toast.makeText(con, "Added to Calendar..",
									Toast.LENGTH_SHORT).show();
						}

					}

					@SuppressWarnings("deprecation")
					@SuppressLint("NewApi")
					public void addToCalendar_champ(Context ctx,
							final String title, final String desc,
							final String tit, final long dtstart,
							final long dtend) {

						Uri eventsUri, reminderuri;

						if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 14) {
							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");
							// //
							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, tit);
							event.put(Events.DESCRIPTION, "SPORTIZZA");
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.EVENT_COLOR, Color.GREEN);

							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							// To Insert
							Log.v("suraj", "Event ="
									+ TimeZone.getDefault().getID());

							Uri uri = ctx.getContentResolver().insert(
									CalendarContract.Events.CONTENT_URI, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(
									CalendarContract.Reminders.CONTENT_URI,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);

						} else if (Integer
								.parseInt(android.os.Build.VERSION.SDK) >= 8
								&& Integer
										.parseInt(android.os.Build.VERSION.SDK) < 14) {
							//
							eventsUri = Uri
									.parse("content://com.android.calendar/events");
							reminderuri = Uri
									.parse("content://com.android.calendar/reminders");
							// //

							ContentValues event = new ContentValues();

							event.put(Events.CALENDAR_ID, 1);
							event.put(Events.TITLE, tit);
							event.put(Events.DESCRIPTION, "SPORTIZZA");
							event.put(Events.DTSTART, dtstart);
							event.put(Events.DTEND, dtend);
							event.put(Events.STATUS, 1);
							event.put(Events.HAS_ALARM, 1);
							event.put(CalendarContract.Events.EVENT_TIMEZONE,
									TimeZone.getDefault().getID());

							// To Insert
							Log.v("suraj", "Event =" + event);

							Uri uri = ctx.getContentResolver().insert(
									eventsUri, event);

							long eventID = Long.parseLong(uri
									.getLastPathSegment());

							ContentValues reminders = new ContentValues();
							reminders.put(Reminders.EVENT_ID, eventID);
							reminders.put(Reminders.METHOD,
									Reminders.METHOD_ALERT);
							reminders.put(Reminders.MINUTES, 15);

							ctx.getContentResolver().insert(reminderuri,
									reminders);

							Log.v("suraj", "Reminder =" + reminders);
						}

					}
				});

				TextView ch1 = (TextView) add_View
						.findViewById(R.id.new_img_c_channel2_hor);

				if (channel1.equals("null") || channel1.equals("NONE")
						|| channel1 == null) {
					ch1.setText("");
				} else {
					ch1.setText(channel1);
					ch1.setTypeface(sport_font);
				}

				TextView ch2 = (TextView) add_View
						.findViewById(R.id.new_img_c_channel1_hor);
				if (channel2.equals("null") || channel2.equals("NONE")
						|| channel2 == null) {
					ch2.setText("");
				} else {
					ch2.setText(channel2);
					ch2.setTypeface(sport_font);
				}

				TextView ch3 = (TextView) add_View
						.findViewById(R.id.new_img_c_channel3_hor);

				// Log.i("suraj","Chan 3 == "+
				// chan3.equals("null"));
				// Log.v("suraj","Chan 3 == "+
				// chan3.equals(null));

				if (channel3.equals("NONE") || channel3.equals("null")
						|| channel3 == null) {
					ch3.setText("");
				} else {
					ch3.setText(channel3);
					ch3.setTypeface(sport_font);
				}

				// /////////

				final ImageView champ_img = (ImageView) add_View
						.findViewById(R.id.image_champ_hor);

				InputStream is1 = null;

				try {
					is1 = act_con.getResources().getAssets()
							.open("new_sports/" + sp_code + ".png");

					Bitmap res2 = BitmapFactory.decodeStream(is1);

					Log.i("suraj", "" + res2);

					Bitmap output1 = Bitmap.createBitmap(res2.getWidth(),
							res2.getHeight(), Bitmap.Config.ARGB_8888);
					Canvas canvas1 = new Canvas(output1);

					Paint paint = new Paint();
					Rect rect = new Rect(0, 0, res2.getWidth(),
							res2.getHeight());
					RectF rectF = new RectF(rect);
					float roundPx1 = 8f;

					paint.setAntiAlias(true);
					canvas1.drawARGB(0, 0, 0, 0);
					paint.setColor(0xff424242);
					canvas1.drawRoundRect(rectF, roundPx1, roundPx1, paint);
					paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
					canvas1.drawBitmap(res2, rect, rect, paint);

					champ_img.setImageBitmap(output1);
					champ_img.setScaleType(ScaleType.FIT_CENTER);

					final String champ_img_url = ""
							+ StartActivity.get_img_location + "phone/CS/"
							+ champ_data[0] + ".png";
					// new imageTask_champ(champ_img,
					// champ_data[3])
					// .execute(champ_img_url);

					act_con.runOnUiThread(new Runnable() {

						@Override
						public void run() {
							int loader = getImgLoader(sp_code);

							DisplayImageOptions options = new DisplayImageOptions.Builder()
									.cacheInMemory(true).cacheOnDisc(true)
									.showImageForEmptyUri(loader)
									.showImageOnFail(loader)
									.showImageOnLoading(loader).build();

							ImageLoader.getInstance().displayImage(champ_img_url,
									champ_img, options);
						}
					});

				} catch (Exception e) {
					e.printStackTrace();
					try {
						is1 = act_con.getResources().getAssets()
								.open("new_sports/GAM.png");

						Bitmap res2 = BitmapFactory.decodeStream(is1);

						Log.i("suraj", "" + res2);

						Bitmap output1 = Bitmap.createBitmap(res2.getWidth(),
								res2.getHeight(), Bitmap.Config.ARGB_8888);
						Canvas canvas1 = new Canvas(output1);

						Paint paint = new Paint();
						Rect rect = new Rect(0, 0, res2.getWidth(),
								res2.getHeight());
						RectF rectF = new RectF(rect);
						float roundPx1 = 8f;

						paint.setAntiAlias(true);
						canvas1.drawARGB(0, 0, 0, 0);
						paint.setColor(0xff424242);
						canvas1.drawRoundRect(rectF, roundPx1, roundPx1, paint);
						paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
						canvas1.drawBitmap(res2, rect, rect, paint);

						champ_img.setImageBitmap(output1);
						champ_img.setScaleType(ScaleType.FIT_CENTER);

						final String champ_img_url = ""
								+ StartActivity.get_img_location + "phone/CS/"
								+ champ_data[0] + ".png";
						// new imageTask_champ(champ_img,
						// champ_data[3])
						// .execute(champ_img_url);

						act_con.runOnUiThread(new Runnable() {

							@Override
							public void run() {
								int loader = getImgLoader(sp_code);

								DisplayImageOptions options = new DisplayImageOptions.Builder()
										.cacheInMemory(true).cacheOnDisc(true)
										.showImageForEmptyUri(loader)
										.showImageOnFail(loader)
										.showImageOnLoading(loader).build();

								ImageLoader.getInstance().displayImage(champ_img_url,
										champ_img, options);
							}
						});
					} catch (Exception e1) {
					}
				}

				// /////////
				holder.horizontal_layout_ifollow1.addView(linear);

			}

			Bitmap bi_result = null;

			try {
				bi_result = BitmapFactory.decodeStream(con.getResources()
						.getAssets().open("sport_small/" + sp_code + "_S.png"));
			} catch (IOException e1) {
				e1.printStackTrace();
				try {
					bi_result = BitmapFactory.decodeStream(con.getResources()
							.getAssets().open("sport_small/GAM_S.png"));
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			if (bi_result == null) {
				holder.txt_champ_name_ifollow
						.setCompoundDrawablesWithIntrinsicBounds(
								R.drawable.team_selected, 0, 0, 0);

				holder.txt_champ_name_ifollow
						.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
			} else {
				Bitmap bitmap = Bitmap.createScaledBitmap(bi_result, 30, 30,
						true);

				Drawable tmpDraw = (Drawable) new BitmapDrawable(
						con.getResources(), bitmap);

				holder.txt_champ_name_ifollow
						.setCompoundDrawablesWithIntrinsicBounds(tmpDraw, null,
								null, null);
			}

			String tweet_str = Utils.readJsonFeed(
					"http://sportizza.com/interface/ios_twitter_api.php?player_code=-1&champ_code="
							+ champ_data[0] + "&sport_code=-1", con);

			holder.txt_tweet_ifollow.setSelected(true);

			Log.d("suraj", "Tweet String Champion= " + tweet_str);

			if (tweet_str == null || tweet_str.equals("null")) {
				holder.txt_tweet_ifollow.setVisibility(View.GONE);
			} else {
				try {

					JSONArray json_arry = new JSONArray(tweet_str);

					String tweet_string = "";

					for (int i = 0; i < json_arry.length(); i++) {

						JSONObject json_object = json_arry.getJSONObject(i);

						String screen_Name = json_object
								.getString("ss_screen_name");
						String st_tweet = json_object.getString("ss_tw");

						tweet_string = tweet_string + "   "
								+ screen_Name.toUpperCase() + ": " + st_tweet;

					}

					holder.txt_tweet_ifollow.setVisibility(View.VISIBLE);

					holder.txt_tweet_ifollow.setText(tweet_string);
					holder.txt_tweet_ifollow.setSelected(true);
				} catch (Exception e) {
				}
			}

			// }
			// });
			//
			// }
			// }).start();
			// return null;
			// }
			// };
			// wait.execute();
			if (new_video != null) {
				// Thread t = new Thread(new Runnable() {
				//
				// @Override
				// public void run() {
				//
				// act_con.runOnUiThread(new Runnable() {
				//
				// @Override
				// public void run() {

				final String[] champ_data1 = champ_details.split(";");

				holder.horizontal_layout_ifollow2.removeAllViews();

				String Json_result_iyoutube = null;

				// if(champ_sp==""&&player_sp=="")
				// {
				// Json_result_iyoutube =
				// Utils.readJsonFeed("http://sportizza.com/interface/ios_youtube_api.php?player_code="+player_list+"&champ_code="+champ_list+"&sport_code=-1",con);
				//
				// Log.d("suraj_","YOUTUBE JSON IFOLLOW ="+"http://sportizza.com/interface/ios_youtube_api.php?player_code="+player_list+"&champ_code="+champ_list+"&sport_code=-1");
				// }
				// else
				// {
				String Follow_ch = champ_data1[0];

				String ch_sport_f = "-1";
				datadapter.open();

				Cursor get_sport_follow = datadapter
						.getfollowersport(Follow_ch);
				get_sport_follow.moveToFirst();

				datadapter.close();

				if (get_sport_follow.getCount() > 0) {
					do {
						ch_sport_f = get_sport_follow
								.getString(get_sport_follow
										.getColumnIndex("sport_code"));
					} while (get_sport_follow.moveToNext());

				}

				String youtube_video_url = "http://sportizza.com/interface/ios_youtube_api.php?player_code=-1&champ_code="
						+ champ_data1[0] + "&sport_code=" + ch_sport_f + "";

				Log.d("suraj_",
						"YOUTUBE JSON IFOLLOW 22="
								+ "http://sportizza.com/interface/ios_youtube_api.php?player_code=-1&champ_code="
								+ champ_data1[0] + "&sport_code=" + ch_sport_f
								+ "");

				String video_data_result = Utils.readJsonFeed(
						youtube_video_url, con);
				;

				try {

					JSONArray array_entity = null;

					array_entity = new JSONArray(video_data_result);

					int array_len1 = array_entity.length();

					String play_list = null;

					boolean P_flag = true, S_flag = true, C_flag = true;

					ArrayList<String> ent_type = new ArrayList<String>();
					HashMap<String, String> play_hash = new HashMap<String, String>();

					for (int i = 0; i < array_len1; i++) {

						JSONObject jsonObject1 = array_entity.getJSONObject(i);

						String entity_code = jsonObject1
								.getString("ss_entity_code");

						String enity_type = jsonObject1
								.getString("ss_entity_type");

						String ss_youtube_url = jsonObject1
								.getString("ss_youtube_url");

						String pl_ls = ss_youtube_url.substring(ss_youtube_url
								.lastIndexOf("list=") + 1);

						if (!entity_code.equals("ALL")
								&& !entity_code.equals("POP")) {
							play_hash.put(enity_type, pl_ls);
							ent_type.add(enity_type);
						}
					}

					if (ent_type.contains("S")) {
						play_list = play_hash.get("S");
						if (ent_type.contains("C")) {
							play_list = play_hash.get("C");
							if (ent_type.contains("P")) {
								play_list = play_hash.get("P");
							}
						} else if (ent_type.contains("P")) {
							play_list = play_hash.get("P");
						}

					}

					Log.i("suraj_", "Playlist = " + play_list);

					// //////

					String[] play_list_youtube = play_list.split("=");

					Log.w("suraj_", "Video URL ="
							+ "https://gdata.youtube.com/feeds/api/playlists/"
							+ play_list_youtube[1] + "?v=2&alt=jsonc");
					// holder.horizontal_layout_ifollow2.setTag(play_list_youtube[1]);

					if (play_list != null) {
						try {
							String _response = Utils.readJsonFeed(
									"https://gdata.youtube.com/feeds/api/playlists/"
											+ play_list_youtube[1]
											+ "?v=2&alt=jsonc", con);

							JSONObject json = new JSONObject(_response);

							JSONArray jsonArray1 = json.getJSONObject("data")
									.getJSONArray("items");

							JSONObject video_array = null;
							Log.d("suraj_", "jsonArray1.length() = "
									+ jsonArray1.length());

							// holder.progress_video.setVisibility(View.GONE);
							holder.horizontal_layout_ifollow2.removeAllViews();

							int ll;
							if (jsonArray1.length() > 8) {
								ll = 8;
							} else {
								ll = jsonArray1.length();
							}

							for (int i = 0; i < ll; i++) {

								JSONObject jsonObject1 = jsonArray1
										.getJSONObject(i);

								String title1 = jsonObject1.getJSONObject(
										"video").getString("title");
								// title.add(title1);
								//

								if (!title1.equals("Deleted video")) {
									String video_id = jsonObject1
											.getJSONObject("video").getString(
													"id");
									// msg.add(url);
									//
									final String thumbUrl = jsonObject1
											.getJSONObject("video")
											.getJSONObject("thumbnail")
											.getString("sqDefault");
									// thumb.add(thumbUrl);

									View additionView = inflater.inflate(
											R.layout.video_row, null, false);

									final LinearLayout linear = (LinearLayout) additionView
											.findViewById(R.id.video_lin_row);

									additionView.setTag(video_id);

									final ImageView video_thumb = (ImageView) additionView
											.findViewById(R.id.imageView_video_thumb);
									TextView video_title_thumb = (TextView) additionView
											.findViewById(R.id.txt_video_title);

									video_title_thumb.setText(title1);
									video_title_thumb.setTypeface(sport_font);
									Log.d("suraj_", "VideoTitle = " + thumbUrl);

									act_con.runOnUiThread(new Runnable() {

										@Override
										public void run() {

											int loader = R.drawable.videos;

											DisplayImageOptions options = new DisplayImageOptions.Builder()
													.cacheInMemory(true).cacheOnDisc(true)
													.showImageForEmptyUri(loader)
													.showImageOnFail(loader)
													.showImageOnLoading(loader).build();

											ImageLoader.getInstance().displayImage(thumbUrl,
													 video_thumb, options);
										}
									});

									holder.horizontal_layout_ifollow2
											.addView(linear);

									linear.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View arg0) {

											// TODO Auto-generated method stub
											Intent data = new Intent(act_con,
													Sample_Act_youtube.class);
											data.putExtra("video_id", linear
													.getTag().toString());
											act_con.startActivity(data);

										}

									});
								}
							}

						} catch (Exception e1) {
							e1.printStackTrace();
						}
					} else {
						holder.horizontal_layout_ifollow2
								.setVisibility(View.GONE);
						holder.new_layout_gap.setVisibility(View.GONE);
					}
					// /////

				} catch (Exception e) {
					// TODO: handle exception
				}

				// }
				// });
				//
				// }
				// });
				// t.start();
			} else {
				holder.horizontal_layout_ifollow2.setVisibility(View.GONE);
				holder.new_layout_gap.setVisibility(View.GONE);
			}
		}

		return view;
	}

	static class ViewHolder {
		TextView video_txt_name;
		// ProgressBar progress_ifollow;
		LinearLayout horizontal_layout_ifollow1;
		LinearLayout horizontal_layout_ifollow2;
		// HorizontalScrollView horizontal_ifollow1;
		// HorizontalScrollView horizontal_ifollow2;
		TextView txt_champ_name_ifollow;
		TextView txt_sport_name_ifollow;
		LinearLayout new_layout_gap;
		TextView txt_tweet_ifollow;
		ProgressBar progress_video;

		// public ViewHolder(LinearLayout
		// horizontal_layout_ifollow1,LinearLayout
		// horizontal_layout_ifollow2,TextView txt_champ_name_ifollow,TextView
		// txt_sport_name_ifollow,TextView txt_tweet_ifollow)
		// {
		// this.horizontal_layout_ifollow1=horizontal_layout_ifollow1;
		// this.horizontal_layout_ifollow2=horizontal_layout_ifollow2;
		// this.txt_champ_name_ifollow=txt_champ_name_ifollow;
		// this.txt_sport_name_ifollow=txt_sport_name_ifollow;
		// this.txt_tweet_ifollow=txt_tweet_ifollow;
		// }
	}

	private class imageTask extends AsyncTask<String, Void, Bitmap> {
		ImageView imageView = null;

		String sp_code = null;

		imageTask(ImageView iv, String sport_code) {
			this.imageView = iv;
			this.sp_code = sport_code;
		}

		@Override
		protected Bitmap doInBackground(String... params) {
			try {
				return download_Image(params[0]);

			} catch (OutOfMemoryError e) {
				return null;
			}
		}

		@Override
		protected void onPostExecute(Bitmap result) {

			Bitmap output = null;
			Canvas canvas;
			float roundPx;
			if (result == null) {

				InputStream is = null;
				try {
					is = con.getResources().getAssets()
							.open("new_sports/" + sp_code + ".png");

					result = BitmapFactory.decodeStream(is);
				} catch (Exception e) {
					try {
						is = con.getResources().getAssets()
								.open("new_sports/GAM.png");
					} catch (IOException e1) {
					}

					result = BitmapFactory.decodeStream(is);
				}

				output = Bitmap.createBitmap(result.getWidth(),
						result.getHeight(), Bitmap.Config.ARGB_8888);
				canvas = new Canvas(output);

				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, result.getWidth(),
						result.getHeight());
				RectF rectF = new RectF(rect);
				roundPx = 8f;

				paint.setAntiAlias(true);
				canvas.drawARGB(0, 0, 0, 0);
				paint.setColor(0xff424242);
				canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
				paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
				canvas.drawBitmap(result, rect, rect, paint);

				imageView.setImageBitmap(output);
				// imageView.setScaleType(ScaleType.FIT_CENTER);

			} else {

				output = Bitmap.createBitmap(result.getWidth(),
						result.getHeight(), Bitmap.Config.ARGB_8888);
				canvas = new Canvas(output);

				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, result.getWidth(),
						result.getHeight());
				RectF rectF = new RectF(rect);
				roundPx = 8f;

				paint.setAntiAlias(true);
				canvas.drawARGB(0, 0, 0, 0);
				paint.setColor(0xff424242);
				canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
				paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
				canvas.drawBitmap(result, rect, rect, paint);

				imageView.setImageBitmap(output);
				// imageView.setScaleType(ScaleType.FIT_CENTER);
			}

			super.onPostExecute(result);
		}

		private Bitmap download_Image(String url) {
			// ---------------------------------------------------
			Bitmap bm = null;
			try {
				URL aURL = new URL(url);
				URLConnection conn = aURL.openConnection();
				conn.connect();
				InputStream is = conn.getInputStream();
				BufferedInputStream bis = new BufferedInputStream(is);
				bm = BitmapFactory.decodeStream(bis);
				bis.close();
				is.close();
			} catch (Exception e) {
				Log.e("Hub", "Error getting the image from server : ");

				InputStream iss = null;
				try {
					iss = con.getResources().getAssets()
							.open("new_sports/" + sp_code + ".png");
				} catch (IOException e1) {
					e1.printStackTrace();
					try {
						iss = con.getResources().getAssets()
								.open("new_sports/GAM.png");
					} catch (IOException e2) {
						// TODO Auto-generated catch block
						e2.printStackTrace();
					}
				}
				return BitmapFactory.decodeStream(iss);

			}
			return bm;

		}

	}

	/*
	 * private class imageTask_champ extends AsyncTask<String, Void, Bitmap> {
	 * ImageView imageView = null; String sp_code = null;
	 * 
	 * imageTask_champ(ImageView iv, String champ_data) { this.imageView = iv;
	 * this.sp_code = champ_data; }
	 * 
	 * @Override protected Bitmap doInBackground(String... params) { try {
	 * return download_Image(params[0]);
	 * 
	 * } catch (OutOfMemoryError e) { return null; }
	 * 
	 * }
	 * 
	 * @Override protected void onPostExecute(Bitmap result) { Bitmap output;
	 * Canvas canvas; float roundPx;
	 * 
	 * if (result == null) {
	 * 
	 * InputStream is = null;
	 * 
	 * try {
	 * 
	 * is = act_con .getResources() .getAssets() .open("new_sports/" + sp_code +
	 * ".png");
	 * 
	 * result = BitmapFactory.decodeStream(is);
	 * 
	 * } catch (Exception e) { try { is = act_con .getResources() .getAssets()
	 * .open("new_sports/GAM.png");
	 * 
	 * result = BitmapFactory.decodeStream(is); } catch (IOException e1) { //
	 * TODO Auto-generated catch block e1.printStackTrace(); } }
	 * 
	 * output = Bitmap.createBitmap(result.getWidth(), result.getHeight(),
	 * Bitmap.Config.ARGB_8888); canvas = new Canvas(output);
	 * 
	 * Paint paint = new Paint(); Rect rect = new Rect(0, 0, result.getWidth(),
	 * result.getHeight()); RectF rectF = new RectF(rect); roundPx = 8f;
	 * 
	 * paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);
	 * paint.setColor(0xff424242); canvas.drawRoundRect(rectF, roundPx, roundPx,
	 * paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
	 * canvas.drawBitmap(result, rect, rect, paint);
	 * 
	 * imageView.setImageBitmap(output);
	 * imageView.setScaleType(ScaleType.FIT_CENTER);
	 * 
	 * } else { output = Bitmap.createBitmap(result.getWidth(),
	 * result.getHeight(), Bitmap.Config.ARGB_8888); canvas = new
	 * Canvas(output);
	 * 
	 * Paint paint = new Paint(); Rect rect = new Rect(0, 0, result.getWidth(),
	 * result.getHeight()); RectF rectF = new RectF(rect); roundPx = 8f;
	 * 
	 * paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);
	 * paint.setColor(0xff424242); canvas.drawRoundRect(rectF, roundPx, roundPx,
	 * paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
	 * canvas.drawBitmap(result, rect, rect, paint);
	 * 
	 * imageView.setImageBitmap(output);
	 * 
	 * } super.onPostExecute(result); }
	 * 
	 * private Bitmap download_Image(String url) { //
	 * --------------------------------------------------- Bitmap bm = null; try
	 * { URL aURL = new URL(url); URLConnection conn = aURL.openConnection();
	 * conn.connect(); InputStream is = conn.getInputStream();
	 * BufferedInputStream bis = new BufferedInputStream(is); bm =
	 * BitmapFactory.decodeStream(bis); bis.close(); is.close(); } catch
	 * (Exception e) { Log.e("Hub", "Error getting the image from server : ");
	 * InputStream iss = null; try { iss = act_con.getResources().getAssets()
	 * .open("new_sports/" + sp_code + ".png"); } catch (IOException e1) {
	 * e1.printStackTrace(); try { iss = act_con.getResources().getAssets()
	 * .open("new_sports/GAM.png"); } catch (IOException e2) { // TODO
	 * Auto-generated catch block e2.printStackTrace(); } } return
	 * BitmapFactory.decodeStream(iss); }
	 * 
	 * return bm;
	 * 
	 * }
	 * 
	 * }
	 */

	public int getImgLoader(String sport_code) {

		int loader = R.drawable.gam;

		if (sport_code.equalsIgnoreCase("AFT")) {
			loader = R.drawable.aft;
		} else if (sport_code.equalsIgnoreCase("TT")) {
			loader = R.drawable.tt;
		} else if (sport_code.equalsIgnoreCase("POL")) {
			loader = R.drawable.pol;
		} else if (sport_code.equalsIgnoreCase("SWI")) {
			loader = R.drawable.swi;
		} else if (sport_code.equalsIgnoreCase("UFC")) {
			loader = R.drawable.ufc;
		} else if (sport_code.equalsIgnoreCase("BAD")) {
			loader = R.drawable.bad;
		} else if (sport_code.equalsIgnoreCase("BB")) {
			loader = R.drawable.bb;
		} else if (sport_code.equalsIgnoreCase("CRI")) {
			loader = R.drawable.cri;
		} else if (sport_code.equalsIgnoreCase("F1")) {
			loader = R.drawable.f1;
		} else if (sport_code.equalsIgnoreCase("GAM")) {
			loader = R.drawable.gam;
		} else if (sport_code.equalsIgnoreCase("GOL")) {
			loader = R.drawable.gol;
		} else if (sport_code.equalsIgnoreCase("HOC")) {
			loader = R.drawable.hoc;
		} else if (sport_code.equalsIgnoreCase("ICE")) {
			loader = R.drawable.ice;
		} else if (sport_code.equalsIgnoreCase("IND")) {
			loader = R.drawable.ind;
		} else if (sport_code.equalsIgnoreCase("MGP")) {
			loader = R.drawable.mgp;
		} else if (sport_code.equalsIgnoreCase("NAS")) {
			loader = R.drawable.nas;
		} else if (sport_code.equalsIgnoreCase("OLY")) {
			loader = R.drawable.oly;
		} else if (sport_code.equalsIgnoreCase("RUG")) {
			loader = R.drawable.rug;
		} else if (sport_code.equalsIgnoreCase("SBK")) {
			loader = R.drawable.sbk;
		} else if (sport_code.equalsIgnoreCase("SOC")) {
			loader = R.drawable.soc;
		} else if (sport_code.equalsIgnoreCase("SPO")) {
			loader = R.drawable.spo;
		} else if (sport_code.equalsIgnoreCase("SQU")) {
			loader = R.drawable.squ;
		} else if (sport_code.equalsIgnoreCase("TEN")) {
			loader = R.drawable.ten;
		} else if (sport_code.equalsIgnoreCase("V8C")) {
			loader = R.drawable.v8c;
		} else if (sport_code.equalsIgnoreCase("WRC")) {
			loader = R.drawable.wrc;
		} else {
			loader = R.drawable.gam;
		}
		return loader;
	}
}
